/*
 * @Author: @yzcheng
 * @Date: 2021-04-17 18:14:09
 * @Version: 1.0
 * @LastEditors: @yzcheng
 * @Description:
 * @LastEditTime: 2021-06-11 11:16:48
 */
import request from '@/utils/request'
import { CHECC_API_BASE_DATA, CHECC_API_CMS,CHECC_AM_ROUTINE_MAINTENANCE } from '@/constants/proxy'
import { ObjectType, ResponseDataPromise } from '../../typings/interfaces'
import * as proxy from '@/constants/proxy'


export function requestRoadSurfaceList({ data, params }): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-road-structure/page`,
    method: 'post',
    params,
    data
  })
}

export function requestStructureMaterialList(params: any): Promise<any> {
  const str = params.codeList.reduce((rst, cur) => {
    if(rst === '?'){
      rst += `codeList%5B%5D=${cur}`
    }else{
      rst += `&codeList%5B%5D=${cur}`
    }
    return rst
  }, '?')
  return request({
    url: CHECC_API_BASE_DATA + `/bd-structure-material` + str,
    method: 'get',
  })
}

export function addRoadSurfaceData(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-road-structure`,
    method: 'post',
    data,
  })
}

export function updateRoadSurfaceData(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-road-structure`,
    method: 'put',
    data,
  })
}

export function delRoadSurfaceData(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-road-structure`,
    method: 'delete',
    data
  })
}

export function getBdRoute({ data, params }: any) {
  return request({
    url: CHECC_API_BASE_DATA + '/bdRoute2/page',
    method: 'post',
    data,
    params,
  })
}

export function requestDictCodeList(data: any): Promise<any> {
  return request({
    url: CHECC_API_CMS + `/dictItem/codelist`,
    method: 'post',
    data: data.dictCodeList,
  })
}

export function setRoadSurfaceDataLock(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-road-structure/lock`,
    method: 'post',
    data,
  })
}

export const exportSurfaceRecordsRequest = (): ResponseDataPromise<ObjectType> =>
  request({
    url: CHECC_API_BASE_DATA + '/bd-road-structure/export',
    method: 'post',
  })
  // 通过id查询数据
export const requestSurfaceData = (data: any): ResponseDataPromise<ObjectType> =>
  request({
    url: CHECC_API_BASE_DATA + `/bd-road-structure/${data}`,
    method: 'get',
  })